package com.ruoyi.project.info.history.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.info.history.domain.PayHistory;
import com.ruoyi.project.info.history.service.IPayHistoryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 返佣明细Controller
 *
 * @author wzm
 * @date 2022-09-07
 */
@Controller
@RequestMapping("/info/history")
public class PayHistoryController extends BaseController
{
    private String prefix = "info/history";

    @Autowired
    private IPayHistoryService payHistoryService;

    @RequiresPermissions("info:history:view")
    @GetMapping()
    public String history()
    {
        return prefix + "/history";
    }

    /**
     * 查询返佣明细列表
     */
    @RequiresPermissions("info:history:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PayHistory payHistory)
    {
        startPage();
        List<PayHistory> list = payHistoryService.selectPayHistoryList(payHistory);
        return getDataTable(list);
    }

    /**
     * 导出返佣明细列表
     */
    @RequiresPermissions("info:history:export")
    @Log(title = "返佣明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PayHistory payHistory)
    {
        List<PayHistory> list = payHistoryService.selectPayHistoryList(payHistory);
        ExcelUtil<PayHistory> util = new ExcelUtil<PayHistory>(PayHistory.class);
        return util.exportExcel(list, "返佣明细数据");
    }

    /**
     * 新增返佣明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存返佣明细
     */
    @RequiresPermissions("info:history:add")
    @Log(title = "返佣明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PayHistory payHistory)
    {
        payHistory.preInsert();
        return toAjax(payHistoryService.insertPayHistory(payHistory));
    }

    /**
     * 修改返佣明细
     */
    @RequiresPermissions("info:history:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PayHistory payHistory = payHistoryService.selectPayHistoryById(id);
        mmap.put("payHistory", payHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存返佣明细
     */
    @RequiresPermissions("info:history:edit")
    @Log(title = "返佣明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PayHistory payHistory)
    {
        payHistory.preUpdate();
        return toAjax(payHistoryService.updatePayHistory(payHistory));
    }

    /**
     * 删除返佣明细
     */
    @RequiresPermissions("info:history:remove")
    @Log(title = "返佣明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(payHistoryService.deletePayHistoryByIds(ids));
    }
}
